package com.cssy.xxkj.logic.web;

import com.cssy.authority.service.IScUserRolewhPlaceService;
import com.cssy.xxkj.basic.entity.BasicWorkshopDO;
import com.cssy.xxkj.basic.service.IBasicWorkshopService;
import com.cssy.xxkj.logic.contants.BillStatusUtil;
import com.cssy.xxkj.logic.dao.LogicWarehouseHistoryDAO;
import com.cssy.xxkj.logic.dao.LogicWarehousePriceDetailsDAO;
import com.cssy.xxkj.logic.entity.*;
import com.cssy.xxkj.logic.entity.vo.LogicSalesPiCodeVO;
import com.cssy.xxkj.logic.entity.vo.LogicWarehouseDetailsVO;
import com.cssy.xxkj.logic.entity.vo.LogicWarehouseEndMonthSumVO;
import com.cssy.xxkj.logic.entity.vo.LogicWarehouseInventoryVO;
import com.cssy.xxkj.logic.service.*;
import com.cssy.xxkj.logic.util.ExcelUtils;
import com.cssy.xxkj.logic.util.OftenMothedUtil;
import com.cssy.yd.logic.util.SqlUtil;
import com.plat.exception.SyBaseException;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchCondition;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.DateUtils;
import com.plat.util.ExcelUtil;
import com.plat.util.json.OutJsonGrid;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
@RequestMapping("/logic/Reports")
public class ReportsController {

	private static final Logger log = Logger.getLogger(ReportsController.class);

	public static final String WHI="/xxkj/logic/reports/WHInventoryReport";// 库存报表

	public static final String IOS="/xxkj/logic/reports/InOutStorage"; //出入库明细

	public static final String DDR="/xxkj/logic/reports/DayDailyReport"; //日报表

	public static final String MDR="/xxkj/logic/reports/MonthDailyReport"; //月报表

	public static final String PICODE="/xxkj/logic/reports/PiCodeReport"; //PI报表

	public static final String PATCHINGSUM = "/xxkj/logic/reports/PatchSumReport";//派工汇总表

	public static final String DGDETAILS="/xxkj/logic/reports/dispatchingDetatlsReport";//派工明细表

	public static final String COLLECTDGDETAILS="/xxkj/logic/reports/collectDispatchingDetatlsReport";//派工明细表 （汇总）

	public static final String PRICE = "/xxkj/logic/reports/PriceMaterReport";//物料单价

	private static final String SALE = "/xxkj/logHInventoryic/reports/SaleOrderReport";//销售订单明细报表

	private static final String PCSWSUM = "/xxkj/logic/reports/PcsWareSumReport";//采购订单汇总表

	private static final String PCSWDET = "/xxkj/logic/reports/PcsWareDetailReport";//采购订单详细表

	private static final String STOREAll="/xxkj/logic/reports/storeReport";//库存明细报表

	private static final String ENDMONTH = "/xxkj/logic/reports/EndMonthReport";//月末库存汇总表

	@Resource(name = "logicWarehouseInventoryService")
	private ILogicWarehouseInventoryService logicWarehouseInventoryService;

	@Resource(name="scUserRolePlaceService")
	private IScUserRolewhPlaceService scUserRolePlaceService;

	@Resource(name="logicWarehouseDetailsService")
	private ILogicWarehouseDetailsService logicWarehouseDetailsService;

	@Resource(name = "logicSalesService")
	ILogicSalesService logicSalesService;

	@Resource(name = "logicProductionPlanService")
	private ILogicProductionPlanService logicProductionPlanService;

	@Resource(name = "logicProductionStorageInService")
	private ILogicProductionStorageInService logicProductionStorageInService;

	@Resource(name = "logicProductionStorageOutService")
	private ILogicProductionStorageOutService logicProductionStorageOutService;

	@Resource(name = "basicWorkshopService")//车间管理
	private IBasicWorkshopService basicWorkshopService;

	@Resource(name="logicProductionDispatchingService")
	private ILogicProductionDispatchingService logicProductionDispatchingService;

	//物品平均单价历史表
	@Resource(name = "logicWarehousePriceDetailsDAO")
	private LogicWarehousePriceDetailsDAO logicWarehousePriceDetailsDAO;

	@Resource(name="excelExportService")
	private IExcelExportService excelExportService;

	//盘点
	@Resource(name="logicWhCheckTaskService")
	private ILogicWhCheckTaskService logicWhCheckTaskService;

	@Resource(name = "reportsService")
	private IReportsService reportsService;

	@Resource(name = "oftenMothedUtil")
	private OftenMothedUtil oftenMothedUtil;

	@Resource(name = "logicReportsUtilService")
	private ILogicReportsUtilService logicReportsUtilService;

	@Resource(name="logicWarehouseHistoryDAO")
	private LogicWarehouseHistoryDAO logicWarehouseHistoryDAO;

	@RequestMapping("/HInventory")
	public String WHInventory(HttpServletRequest request, Model model){
		model.addAttribute("wh",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return WHI;
	}
	@SuppressWarnings("unchecked")
	@RequestMapping("/WHInventoryList")
	public void WHInventoryList(HttpServletRequest request,
			HttpServletResponse response, Model model){
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		scs.setRemovedProperty("logic_warehouse_inventory.removed");
		Map<String,Object> sqlWHMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"logic_warehouse_inventory.zd001WhCode");
		scs.addCondition(sqlWHMap.get("option")+"",(List<String>)sqlWHMap.get("roleWhList"));
		scs.addCondition("logic_warehouse_inventory.zd009Quantity", 0 , SearchCondition.OP_DY);
		SearchResult result=logicWarehouseInventoryService.findForWareHouseStockByExample(scs);
		List<LogicWarehouseInventoryVO> lwi=result.getResults();
		for(LogicWarehouseInventoryVO lv:lwi){
			if(lv.getZd009Quantity()==null){
				lv.setZd009Quantity(new BigDecimal(0f));
			}
			if(lv.getZd011TravelingQuantity()==null){
				lv.setZd011TravelingQuantity(new BigDecimal(0f));
			}
			lv.setStocks(lv.getZd009Quantity().add(lv.getZd011TravelingQuantity()));
			if(null == lv.getZd024Price()){
				lv.setZd024Price(BigDecimal.ZERO);
			}
			if(null == lv.getZd024Price()){
				lv.setZd024Price(BigDecimal.ZERO);
			}
			lv.setStockPrice(lv.getZd009Quantity().multiply(lv.getZd024Price()));
		}
		result.setResults(lwi);
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
	}
	//库存报表导出
	@SuppressWarnings("unchecked")
	@RequestMapping("/HInventoryExcel")
	public void HInventoryExcel(HttpServletRequest request,
			HttpServletResponse response, Model model){
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		scs.clearCondition();
		try {
			log.info("库存数据下载开始");
			hander.setFilters(new String(request.getParameter("filters").getBytes("ISO-8859-1"), "UTF-8"));
			hander.getWheres(scs);
			scs.setRemovedProperty("logic_warehouse_inventory.removed");
			Map<String,Object> sqlWHMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"logic_warehouse_inventory.zd001WhCode");
			scs.addCondition(sqlWHMap.get("option")+"",(List<String>)sqlWHMap.get("roleWhList"));
			if(scs.getOrderBy()==null){
				scs.setOrderBy("zd009Quantity desc");
			}
			scs.setLimitClause(null);
			scs.addCondition("logic_warehouse_inventory.zd009Quantity", 0 , SearchCondition.OP_DY);
			SearchResult result=logicWarehouseInventoryService.findForWareHouseStockByExample(scs);
			long count=result.getRecordCount();
			List<LogicWarehouseInventoryVO> lwi=result.getResults();
			log.info("获取到查询数据:" + lwi.size());
			List<LogicWarehouseInventoryVO> lvo=new ArrayList<LogicWarehouseInventoryVO>();
			if(count==0){
				new ExcelUtils().toExcel(lwi, "仓库编码:zd001WhCode┋仓库名称:zd001WhName"
						+ "┋物料编码:zd004MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel"
						+ "┋物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity"
						+ "┋单位:zd008Unit┋PI号:zd026PiCode"
						+ "┋客户名称(本项只对成品生效):zd028CustomerName┋入库价格:zd024Price┋总库存:zd009Quantity┋库存金额:stockPrice"
						+ "┋材料编码:zd001Code┋材料名称:zd002Name┋物料类型:zd002MaterialsTypeName"
						+ "┋型号:zd004Model┋尺寸:zd026Size┋颜色:zd033Color┋材质:zd034Quality"
						+ "┋进货价:zd009Price┋基本单位:zd002UnitName", "库存列表", response);
			}else{
				for(LogicWarehouseInventoryVO lv:lwi){
					if(lv.getZd009Quantity()==null||lv.getZd009Quantity().compareTo(BigDecimal.ZERO)==0){
						continue;
					}
					if(null == lv.getZd024Price()){
						lv.setZd024Price(BigDecimal.ZERO);
					}
					lv.setStockPrice(lv.getZd009Quantity().multiply(lv.getZd024Price()));
					lvo.add(lv);
				}

				log.info("组装后的查询数据:" + lvo.size());
				new ExcelUtils().toExcel(lvo, "仓库编码:zd001WhCode┋仓库名称:zd001WhName"
						+ "┋物料编码:zd004MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel"
						+ "┋物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity"
						+ "┋单位:zd008Unit┋PI号:zd026PiCode"
						+ "┋客户名称(本项只对成品生效):zd028CustomerName┋入库价格:zd024Price┋总库存:zd009Quantity┋库存金额:stockPrice"
						+ "┋材料编码:zd001Code┋材料名称:zd002Name┋物料类型:zd002MaterialsTypeName"
						+ "┋型号:zd004Model┋尺寸:zd026Size┋颜色:zd033Color┋材质:zd034Quality"
						+ "┋进货价:zd009Price┋基本单位:zd002UnitName", "库存列表", response);
				log.info("数据生成完毕");
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} 
	}
	
	@RequestMapping("/InOutStorage")
	public String inOutStorage(HttpServletRequest request, Model model){
		model.addAttribute("wh",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return IOS;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/InOutStorageList")
	public void inOutStorageList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		if(StringUtils.isEmpty(scs.getOrderBy())){
			scs.setOrderBy("bizCreatorDate desc");
		}
		Map<String,Object> sqlWHMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"zd003WhCode");
		scs.addCondition(sqlWHMap.get("option")+"",(List<String>)sqlWHMap.get("roleWhList"));
		SearchResult result= logicWarehouseDetailsService.findListByExample(scs);
		List<LogicWarehouseDetailsDO> ld=result.getResults();
		for(LogicWarehouseDetailsDO lwd:ld){
			if(lwd.getZd011BasicQuantity().compareTo(BigDecimal.ZERO)>-1){//把Zd010Quantity为出库数量
				lwd.setZd010Quantity(BigDecimal.ZERO);
			}else{
				lwd.setZd010Quantity(lwd.getZd011BasicQuantity().abs());
				lwd.setZd011BasicQuantity(BigDecimal.ZERO);
			}
		}
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
	}
	//出入库明细报表导出
	@RequestMapping("/InOutStorageExcel")
	public void inOutStorageExcel(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		String type=request.getParameter("type");//1 代表材料  0 代表成品
		List<LogicWarehouseDetailsDO> list= reportsService.finListByConditions(request);
		if(type.equals("0")){//成品
			new ExcelUtils().toExcel(list, "单据编号:zd001BillCode┋单据类型:zd002BillType┋仓库名称:zd003WhName┋"
					+ "物料编码:zd005MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel┋"
					+ "物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity┋"
					+ "单位:zd009BasicUnit┋PI号:zd020PiCode┋客户:zd022ConsumerName┋供应商:zd004WhPositionId┋入库数量:zd011BasicQuantity┋"
					+ "出库数量:zd010Quantity┋单价:zd013Price┋日期:zd016Remark┋业务员:zd004WhPositionName┋描述:zd021Decript" , "出入库明细", response);
		}else{
			new ExcelUtils().toExcel(list, "单据编号:zd001BillCode┋领料单据号(入库单号):zd004WhPositionCode┋单据类型:zd002BillType┋仓库名称:zd003WhName┋"
					+ "物料编码:zd005MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel┋"
					+ "物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity┋"
					+ "单位:zd009BasicUnit┋PI号:zd020PiCode┋客户:zd022ConsumerName┋入库数量:zd011BasicQuantity┋"
					+ "出库数量:zd010Quantity┋单价:zd013Price┋日期:zd016Remark┋描述:zd021Decript" , "出入库明细", response);
		}
/*		List<LogicWarehouseDetailsDO> listWD=new ArrayList<LogicWarehouseDetailsDO>();
		for(int i = 0 ;i<list.size();i++){
			listWD.add(list.get(i));
			if(i%500==0||(i+1)==list.size()){
				listWD=new ArrayList<LogicWarehouseDetailsDO>();
			}
		}*/
		
		
	}
	
	
	@RequestMapping("/dayreport")
	public String dayReport(HttpServletRequest request, Model model){
		model.addAttribute("wh",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return DDR;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/dayreportlist")
	public void dayReportList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		scs.setRemovedProperty("details.removed");
		Map<String,Object> sqlWHMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"details.zd003WhCode");
		scs.addCondition(sqlWHMap.get("option")+"",(List<String>)sqlWHMap.get("roleWhList"));
		scs.addCondition("details.bizCreatorDate", DateUtils.dateToString(new Date(), "yyyy-MM-dd 00:00:00"), SearchCondition.OP_GREATER);
		SearchResult result= logicWarehouseDetailsService.findDaliyReport(scs);
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
	}
	@SuppressWarnings("unchecked")
	@RequestMapping("/dayreportExcel")
	public void dayreportExcel(HttpServletRequest request, 
			HttpServletResponse response){
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		scs.clearCondition();
		try {
			hander.setFilters(new String(request.getParameter("filters").getBytes(
					"ISO-8859-1"), "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		hander.getWheres(scs);
		scs.setRemovedProperty("details.removed");
		Map<String,Object> sqlWHMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"details.zd003WhCode");
		scs.addCondition(sqlWHMap.get("option")+"",(List<String>)sqlWHMap.get("roleWhList"));
		scs.addCondition("details.bizCreatorDate", DateUtils.dateToString(new Date(), "yyyy-MM-dd 00:00:00"), SearchCondition.OP_GREATER);
		SearchResult result= logicWarehouseDetailsService.findDaliyReport(scs);
		Long count=result.getRecordCount();
		Long size= 0l;
		List<LogicWarehouseDetailsVO> list= result.getResults();
		List<LogicWarehouseDetailsVO> viewList= new ArrayList<LogicWarehouseDetailsVO>();
		if(count==null||count==0){
			ExcelUtil.toExcel(viewList,"仓库编码:zd003WhCode┋仓库名称:zd003WhName"
					+ "┋物料编码:zd005MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel"
					+ "┋物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity"
					+ "┋单位:zd009BasicUnit┋PI号:zd020PiCode┋当前库存:zd011BasicQuantity"
					+ "┋本月期初库存:beginningQuantity┋入库数量:inQuantity"
					+ "┋出库库存:outQuantity┋反审数:cbQuantity", "日报", response);
		}else{
			for(LogicWarehouseDetailsVO ld:list){
				size++;
				if(ld.getBeginningQuantity()==null||StringUtils.isNotBlank(ld.getBeginningQuantity()+"")){
					ld.setBeginningQuantity(ld.getZd011BasicQuantity().subtract(ld.getOutQuantity()).subtract(ld.getInQuantity()).subtract(ld.getCbQuantity()));
				}
				viewList.add(ld);
			}
			ExcelUtil.toExcel(viewList,"仓库编码:zd003WhCode┋仓库名称:zd003WhName"
					+ "┋物料编码:zd005MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel"
					+ "┋物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity"
					+ "┋单位:zd009BasicUnit┋PI号:zd020PiCode┋当前库存:zd011BasicQuantity"
					+ "┋本月期初库存:beginningQuantity┋入库数量:inQuantity"
					+ "┋出库库存:outQuantity┋反审数:cbQuantity", "日报", response);
			
		}
		
		
	}
	
	
	@RequestMapping("/monthreport")
	public String monthReport(HttpServletRequest request, Model model){
		model.addAttribute("wh",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return MDR;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/monthreportlist")
	public void monthReportList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		scs.setRemovedProperty("details.removed");
		Map<String,Object> sqlWHMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"details.zd003WhCode");
		scs.addCondition(sqlWHMap.get("option")+"",(List<String>)sqlWHMap.get("roleWhList"));
		scs.addCondition("details.bizCreatorDate", DateUtils.dateToString(DateUtils.getMonthBegin(new Date()), "yyyy-MM-dd 00:00:00"), SearchCondition.OP_GREATER);
		SearchResult result= logicWarehouseDetailsService.findDaliyReport(scs);
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
	}
	@SuppressWarnings("unchecked")
	@RequestMapping("/monthreportExcel")
	public  void monthreportExcel(HttpServletRequest request, 
			HttpServletResponse response){
		JqGridHandler hander= new JqGridHandler(request);
		SearchConditions scs=new SearchConditions();
		scs.clearCondition();
		try {
			hander.setFilters(new String(request.getParameter("filters").getBytes(
					"ISO-8859-1"), "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		hander.getWheres(scs);
		scs.setRemovedProperty("details.removed");
		Map<String,Object> sqlWHMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"details.zd003WhCode");
		scs.addCondition(sqlWHMap.get("option")+"",(List<String>)sqlWHMap.get("roleWhList"));
		scs.addCondition("details.bizCreatorDate", DateUtils.dateToString(DateUtils.getMonthBegin(new Date()), "yyyy-MM-dd 00:00:00"), SearchCondition.OP_GREATER);
		SearchResult result= logicWarehouseDetailsService.findDaliyReport(scs);
		Long count=result.getRecordCount();
		Long size= 0l;
		List<LogicWarehouseDetailsVO> list= result.getResults();
		List<LogicWarehouseDetailsVO> viewList= new ArrayList<LogicWarehouseDetailsVO>();
		if(count==null||count==0){
			ExcelUtil.toExcel(viewList,"仓库编码:zd003WhCode┋仓库名称:zd003WhName"
					+ "┋物料编码:zd005MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel"
					+ "┋物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity"
					+ "┋单位:zd009BasicUnit┋PI号:zd020PiCode┋当前库存:zd011BasicQuantity"
					+ "┋本月期初库存:beginningQuantity┋入库数量:inQuantity"
					+ "┋出库库存:outQuantity┋反审数:cbQuantity", "月报", response);
		}else{
			for(LogicWarehouseDetailsVO ld:list){
				size++;
				if(ld.getBeginningQuantity()==null||StringUtils.isNotBlank(ld.getBeginningQuantity()+"")){
					ld.setBeginningQuantity(ld.getZd011BasicQuantity().subtract(ld.getOutQuantity()).subtract(ld.getInQuantity()).subtract(ld.getCbQuantity()));
				}
				viewList.add(ld);
			}
			ExcelUtil.toExcel(viewList,"仓库编码:zd003WhCode┋仓库名称:zd003WhName"
					+ "┋物料编码:zd005MaterialsCode┋物料名称:zd005MaterialsName┋物料型号:zd007MaterialsModel"
					+ "┋物料规格:zd006MaterialsSpec┋物料颜色:zd008MaterialsColor┋物料材质:zd008MaterialsQuanlity"
					+ "┋单位:zd009BasicUnit┋PI号:zd020PiCode┋当前库存:zd011BasicQuantity"
					+ "┋本月期初库存:beginningQuantity┋入库数量:inQuantity"
					+ "┋出库库存:outQuantity┋反审数:cbQuantity", "月报", response);
			
		}
		
	}
	
	@RequestMapping("/picodereport")
	public String piCodeReport(HttpServletRequest request, Model model){
		return PICODE;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/picodereportlist")
	public void piCodeReportList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		List<LogicSalesPiCodeVO> list = new ArrayList<LogicSalesPiCodeVO>();
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);List<String> str =Arrays.asList(BillStatusUtil.SES_STATUS_FOUR,BillStatusUtil.SES_STATUS_SEVEN,BillStatusUtil.SES_STATUS_FOUR,BillStatusUtil.SES_STATUS_FIVE);
		scs.addCondition("zd024Billstatus", str);
		SearchResult result= logicSalesService.findListByExample(scs);
		List<LogicSalesDO> salesList = result.getResults();
		if(salesList!=null&&!salesList.isEmpty()&&salesList.size()>0){
			for(int i=0;i<salesList.size();i++){
				List<LogicSalesItemDO> salesItemList = logicSalesService.findSalesItemList(salesList.get(i).getId());//获取销售订单产品
				if(salesItemList!=null&&!salesItemList.isEmpty()&&salesItemList.size()>0){
					for(int n=0;n<salesItemList.size();n++){
						LogicSalesPiCodeVO salesVo = new LogicSalesPiCodeVO();
						salesVo.setZd001FormCode(salesList.get(i).getZd001FormCode());
						salesVo.setZd002PiCode(salesList.get(i).getZd002PiCode());
						salesVo.setZd006CustomerName(salesList.get(i).getZd006CustomerName());
						salesVo.setZd022SalesMan(salesList.get(i).getZd022SalesMan());
						salesVo.setZd024Billstatus(salesList.get(i).getZd024Billstatus());
						salesVo.setZd025WareStatus(salesList.get(i).getZd025WareStatus());
						salesVo.setZd026WithSingle(salesList.get(i).getZd026WithSingle());
						salesVo.setMaterialsCode(salesItemList.get(n).getZd007MaterialsCode());
						salesVo.setMaterialsModel(salesItemList.get(n).getZd010MaterialsModel());
						salesVo.setMaterialsName(salesItemList.get(n).getZd008MaterialsName());
						salesVo.setMaterialsUnit(salesItemList.get(n).getZd012MaterialsUnit());
						salesVo.setSalesQuantity(salesItemList.get(n).getZd013Quantity());
						list.add(salesVo);
					}
				}
			}
		}
		
		if(list!=null&&!list.isEmpty()&&list.size()>0){
			//填充生产计划单
			for(int i=0;i<list.size();i++){
				SearchConditions pscs = new SearchConditions();
				pscs.addCondition("zd002OriCode",list.get(i).getZd001FormCode(),SearchCondition.OP_EQUAL);
				pscs.addCondition("zd008Billstatus",BillStatusUtil.PROPLAN_BILL_STATUS_FOUR,SearchCondition.OP_EQUAL);
				SearchResult rsPlan=logicProductionPlanService.findListByExample(pscs);
				List<LogicProductionPlanDO> planList=rsPlan.getResults();
				if(planList!=null&&planList.size()>0&&!planList.isEmpty()){
					for(int n=0;n<planList.size();n++){
						List<LogicProductionPlanItemDO> planItemList=logicProductionPlanService.findPlanItemList(planList.get(n).getId());
						for(int k=0;k<planItemList.size();k++){
							if(list.get(i).getMaterialsCode().equals(planItemList.get(k).getZd007MaterialsCode())){
								if(list.get(i).getProPlanCode()==null){
									list.get(i).setProPlanCode(planList.get(n).getZd001FormCode());
								}else{
									list.get(i).setProPlanCode(list.get(i).getProPlanCode()+"|"+planList.get(n).getZd001FormCode());
								}
								if(list.get(i).getPlanQuantity()==null){
									list.get(i).setPlanQuantity(planItemList.get(k).getZd013Quantity());
								}else{
									list.get(i).setPlanQuantity(list.get(i).getPlanQuantity().add(planItemList.get(k).getZd013Quantity()));
								}
							}
						}
					}
				}
			}
			//填充生产入库数量
			for(int i=0;i<list.size();i++){
				SearchConditions pscs = new SearchConditions();
				pscs.addCondition("zd002OriCode",list.get(i).getProPlanCode(),SearchCondition.OP_EQUAL);
				pscs.addCondition("zd011BillStatus",BillStatusUtil.PROSTORIN_STATUS_FIVE,SearchCondition.OP_EQUAL);
				SearchResult rsPlan=logicProductionStorageInService.findListByExample(pscs);
				List<LogicProductionStorageinDO> storageInList=rsPlan.getResults();
				if(storageInList!=null&&storageInList.size()>0&&!storageInList.isEmpty()){
					for(int n=0;n<storageInList.size();n++){
						List<LogicProductionStorageinItemDO> storageInItemList=logicProductionStorageInService.findStorInItemList(storageInList.get(n).getId());
						for(int k=0;k<storageInItemList.size();k++){
							if(list.get(i).getMaterialsCode().equals(storageInItemList.get(k).getZd002MaterialsCode())){
								if(list.get(i).getProStorInCode()==null){
									list.get(i).setProStorInCode(storageInList.get(n).getZd001InCode());
								}else{
									list.get(i).setProStorInCode(list.get(i).getProStorInCode()+"|"+storageInList.get(n).getZd001InCode());
								}
								if(list.get(i).getRkQuantity()==null){
									list.get(i).setRkQuantity(storageInItemList.get(k).getZd007Quantity());
								}else{
									list.get(i).setRkQuantity(list.get(i).getRkQuantity().add(storageInItemList.get(k).getZd007Quantity()));
								}
							}
						}
					}
				}
			}
			//填充销售出库数量
			for(int i=0;i<list.size();i++){
				SearchConditions pscs = new SearchConditions();
				pscs.addCondition("zd002OriCode",list.get(i).getZd001FormCode(),SearchCondition.OP_EQUAL);
				pscs.addCondition("zd011BillStatus",BillStatusUtil.PROSTOROUT_STATUS_FIVE,SearchCondition.OP_EQUAL);
				SearchResult rsPlan=logicProductionStorageOutService.findListByExample(pscs);
				List<LogicProductionStorageoutDO> storageOutList=rsPlan.getResults();
				if(storageOutList!=null&&storageOutList.size()>0&&!storageOutList.isEmpty()){
					for(int n=0;n<storageOutList.size();n++){
						List<LogicProductionStorageoutItemDO> storageOutItemList=logicProductionStorageOutService.findStorOutItemList(storageOutList.get(n).getId());
						for(int k=0;k<storageOutItemList.size();k++){
							if(list.get(i).getMaterialsCode().equals(storageOutItemList.get(k).getZd002MaterialsCode())){
								if(list.get(i).getProStorOutCode()==null){
									list.get(i).setProStorOutCode(storageOutList.get(n).getZd001OutCode());
								}else{
									list.get(i).setProStorOutCode(list.get(i).getProStorOutCode()+"|"+storageOutList.get(n).getZd001OutCode());
								}
								if(list.get(i).getCkQuantity()==null){
									list.get(i).setCkQuantity(storageOutItemList.get(k).getZd007Quantity());
								}else{
									list.get(i).setCkQuantity(list.get(i).getCkQuantity().add(storageOutItemList.get(k).getZd007Quantity()));
								}
							}
						}
					}
				}
			}
		}
		result.setResults(list);
		result.setRecordCount(list.size());
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
	}
	//pi报表导出
	@SuppressWarnings("unchecked")
	@RequestMapping("/picodereportExcel")
	public void picodereportExcel(HttpServletRequest request, 
			HttpServletResponse response){
		SearchConditions scs= new SearchConditions();
		JqGridHandler handler= new JqGridHandler();
		scs.clearCondition();
		try {
			handler.setFilters(new String(request.getParameter("filters").getBytes(
					"ISO-8859-1"), "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		handler.getWheres(scs);
		List<LogicSalesPiCodeVO> list = new ArrayList<LogicSalesPiCodeVO>();
		List<String> str =Arrays.asList(BillStatusUtil.SES_STATUS_FOUR,BillStatusUtil.SES_STATUS_SEVEN,BillStatusUtil.SES_STATUS_FOUR,BillStatusUtil.SES_STATUS_FIVE);
		scs.addCondition("zd024Billstatus", str);
		SearchResult result= logicSalesService.findListByExample(scs);
		List<LogicSalesDO> salesList = result.getResults();
		if(salesList!=null&&!salesList.isEmpty()&&salesList.size()>0){
			for(int i=0;i<salesList.size();i++){
				List<LogicSalesItemDO> salesItemList = logicSalesService.findSalesItemList(salesList.get(i).getId());//获取销售订单产品
				if(salesItemList!=null&&!salesItemList.isEmpty()&&salesItemList.size()>0){
					for(int n=0;n<salesItemList.size();n++){
						LogicSalesPiCodeVO salesVo = new LogicSalesPiCodeVO();
						salesVo.setZd001FormCode(salesList.get(i).getZd001FormCode());
						salesVo.setZd002PiCode(salesList.get(i).getZd002PiCode());
						salesVo.setZd006CustomerName(salesList.get(i).getZd006CustomerName());
						salesVo.setZd022SalesMan(salesList.get(i).getZd022SalesMan());
						salesVo.setZd024Billstatus(salesList.get(i).getZd024Billstatus());
						salesVo.setZd025WareStatus(salesList.get(i).getZd025WareStatus());
						salesVo.setZd026WithSingle(salesList.get(i).getZd026WithSingle());
						salesVo.setMaterialsCode(salesItemList.get(n).getZd007MaterialsCode());
						salesVo.setMaterialsModel(salesItemList.get(n).getZd010MaterialsModel());
						salesVo.setMaterialsName(salesItemList.get(n).getZd008MaterialsName());
						salesVo.setMaterialsUnit(salesItemList.get(n).getZd012MaterialsUnit());
						salesVo.setSalesQuantity(salesItemList.get(n).getZd013Quantity());
						list.add(salesVo);
					}
				}
			}
		}
		
		if(list!=null&&!list.isEmpty()&&list.size()>0){
			//填充生产计划单
			for(int i=0;i<list.size();i++){
				SearchConditions pscs = new SearchConditions();
				pscs.addCondition("zd002OriCode",list.get(i).getZd001FormCode(),SearchCondition.OP_EQUAL);
				pscs.addCondition("zd008Billstatus",BillStatusUtil.PROPLAN_BILL_STATUS_FOUR,SearchCondition.OP_EQUAL);
				SearchResult rsPlan=logicProductionPlanService.findListByExample(pscs);
				List<LogicProductionPlanDO> planList=rsPlan.getResults();
				if(planList!=null&&planList.size()>0&&!planList.isEmpty()){
					for(int n=0;n<planList.size();n++){
						List<LogicProductionPlanItemDO> planItemList=logicProductionPlanService.findPlanItemList(planList.get(n).getId());
						for(int k=0;k<planItemList.size();k++){
							if(list.get(i).getMaterialsCode().equals(planItemList.get(k).getZd007MaterialsCode())){
								if(list.get(i).getProPlanCode()==null){
									list.get(i).setProPlanCode(planList.get(n).getZd001FormCode());
								}else{
									list.get(i).setProPlanCode(list.get(i).getProPlanCode()+"|"+planList.get(n).getZd001FormCode());
								}
								if(list.get(i).getPlanQuantity()==null){
									list.get(i).setPlanQuantity(planItemList.get(k).getZd013Quantity());
								}else{
									list.get(i).setPlanQuantity(list.get(i).getPlanQuantity().add(planItemList.get(k).getZd013Quantity()));
								}
							}
						}
					}
				}
			}
			//填充生产入库数量
			for(int i=0;i<list.size();i++){
				SearchConditions pscs = new SearchConditions();
				pscs.addCondition("zd002OriCode",list.get(i).getProPlanCode(),SearchCondition.OP_EQUAL);
				pscs.addCondition("zd011BillStatus",BillStatusUtil.PROSTORIN_STATUS_FIVE,SearchCondition.OP_EQUAL);
				SearchResult rsPlan=logicProductionStorageInService.findListByExample(pscs);
				List<LogicProductionStorageinDO> storageInList=rsPlan.getResults();
				if(storageInList!=null&&storageInList.size()>0&&!storageInList.isEmpty()){
					for(int n=0;n<storageInList.size();n++){
						List<LogicProductionStorageinItemDO> storageInItemList=logicProductionStorageInService.findStorInItemList(storageInList.get(n).getId());
						for(int k=0;k<storageInItemList.size();k++){
							if(list.get(i).getMaterialsCode().equals(storageInItemList.get(k).getZd002MaterialsCode())){
								if(list.get(i).getProStorInCode()==null){
									list.get(i).setProStorInCode(storageInList.get(n).getZd001InCode());
								}else{
									list.get(i).setProStorInCode(list.get(i).getProStorInCode()+"|"+storageInList.get(n).getZd001InCode());
								}
								if(list.get(i).getRkQuantity()==null){
									list.get(i).setRkQuantity(storageInItemList.get(k).getZd007Quantity());
								}else{
									list.get(i).setRkQuantity(list.get(i).getRkQuantity().add(storageInItemList.get(k).getZd007Quantity()));
								}
							}
						}
					}
				}
			}
			//填充销售出库数量
			for(int i=0;i<list.size();i++){
				SearchConditions pscs = new SearchConditions();
				pscs.addCondition("zd002OriCode",list.get(i).getZd001FormCode(),SearchCondition.OP_EQUAL);
				pscs.addCondition("zd011BillStatus",BillStatusUtil.PROSTOROUT_STATUS_FIVE,SearchCondition.OP_EQUAL);
				SearchResult rsPlan=logicProductionStorageOutService.findListByExample(pscs);
				List<LogicProductionStorageoutDO> storageOutList=rsPlan.getResults();
				if(storageOutList!=null&&storageOutList.size()>0&&!storageOutList.isEmpty()){
					for(int n=0;n<storageOutList.size();n++){
						List<LogicProductionStorageoutItemDO> storageOutItemList=logicProductionStorageOutService.findStorOutItemList(storageOutList.get(n).getId());
						for(int k=0;k<storageOutItemList.size();k++){
							if(list.get(i).getMaterialsCode().equals(storageOutItemList.get(k).getZd002MaterialsCode())){
								if(list.get(i).getProStorOutCode()==null){
									list.get(i).setProStorOutCode(storageOutList.get(n).getZd001OutCode());
								}else{
									list.get(i).setProStorOutCode(list.get(i).getProStorOutCode()+"|"+storageOutList.get(n).getZd001OutCode());
								}
								if(list.get(i).getCkQuantity()==null){
									list.get(i).setCkQuantity(storageOutItemList.get(k).getZd007Quantity());
								}else{
									list.get(i).setCkQuantity(list.get(i).getCkQuantity().add(storageOutItemList.get(k).getZd007Quantity()));
								}
							}
						}
					}
				}
			}
		}
		result.setResults(list);
		result.setRecordCount(list.size());
		ExcelUtil.toExcel(list, "销售单号:zd001FormCode┋PI单号:zd002PiCode┋"
				+ "客户名称:zd006CustomerName┋业务员:zd022SalesMan┋产品编码:materialsCode┋"
				+ "产品名称:materialsName┋产品型号:materialsModel┋产品单位:materialsUnit┋"
				+ "销售订单数量:salesQuantity┋生产计划单号:proPlanCode┋计划数量:planQuantity┋"
				+ "生产入库单:proStorInCode┋生产入库数量:rkQuantity┋销售出库单:proStorOutCode┋"
				+ "销售出库数量:ckQuantity", "PI报表", response);
		
	}
	
	/**
	 * 派工汇总表
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping("/dispatchingSum")
	public String dispatchingSum(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		
		return PATCHINGSUM;
	}
	
	@RequestMapping("/dispatchingSumList")
	public void dispatchingSumList(HttpServletRequest request,
			HttpServletResponse response, Model model){
		JqGridHandler handler= new JqGridHandler(request);
		SearchConditions scs= new SearchConditions();
		handler.getWheres(scs);
		/*if(scs.getOrderBy()==null){
			scs.setOrderBy("logic_production_dispatching_detail.bizCreatorDate");
		}*/
		SearchResult sr= logicProductionDispatchingService.findDispatchingDetailToSum(scs);
		OutJsonGrid out = new OutJsonGrid(sr);
		out.printJSon(response);
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/collectDispatchingDetails")
	public String collectDispatchingDetails(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		SearchConditions scs= new SearchConditions();
		List<BasicWorkshopDO> list=basicWorkshopService.findListByExample(scs).getResults();
		model.addAttribute("ws", list);//车间
		return COLLECTDGDETAILS;
	}
	
	@RequestMapping("/dispatchingDetailsList")
	public void dispatchingDetailsList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		JqGridHandler handler= new JqGridHandler(request);
		SearchConditions scs= new SearchConditions();
		handler.getWheres(scs);
		scs.setRemovedProperty(null);
		scs.setLimitClause(null);
		scs.setOrderBy(null);
		scs=oftenMothedUtil.addSearchConditionsByInMonth(scs, "logic_production_dispatching_detail.zd008WorkDate");
		scs.addCondition("logic_production_dispatching_detail.zd008WorkStatus", BillStatusUtil.PRODISPATDTL_BILL_STATUS_ZONE);
		SearchResult sr= logicProductionDispatchingService.findCollectDispatchingDetailBySCS(scs);
		OutJsonGrid out = new OutJsonGrid(sr);
		out.printJSon(response);
	}
	@RequestMapping("/collectDispatchingDetailsItem")
	public String collectDispatchingDetailsItem(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		try {
			String condition=new String(request.getParameter("condition").getBytes("iso8859-1"),"utf-8");
			String usercode=new String(request.getParameter("usercode").getBytes("iso8859-1"),"utf-8");
			String workshop=new String(request.getParameter("workshop").getBytes("iso8859-1"),"utf-8");
			model.addAttribute("condition", condition);
			model.addAttribute("workshop", workshop);
			model.addAttribute("usercode", usercode);
		} catch (UnsupportedEncodingException e) {
			
			e.printStackTrace();
		}
		
		return DGDETAILS;
	}
	@RequestMapping("/dispatchingDetailsListItem")
	public void dispatchingDetailsListItem(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		SearchConditions scs=new SearchConditions();
		try {
			String usercode=new String(request.getParameter("usercode").getBytes("iso8859-1"),"utf-8");
			String workshop=new String(request.getParameter("workshop").getBytes("iso8859-1"),"utf-8");
			scs= oftenMothedUtil.getNewSearchConditionsPageToJava(request, "condition");
			scs= oftenMothedUtil.addSearchConditionsByInMonth(scs, "logic_production_dispatching_detail.zd008WorkDate");
			scs.addCondition("logic_production_dispatching_detail.zd008WorkStatus", BillStatusUtil.PRODISPATDTL_BILL_STATUS_ZONE);
			scs.addCondition("logic_production_dispatching_detail_item.zd007UseCode", usercode);
			scs.addCondition("logic_production_dispatching_detail_item.zd028WorkShopName", workshop);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		scs.setLimitClause(null);
		scs.setRemovedProperty(null);
		scs.setOrderBy("logic_production_dispatching_detail.zd001FormCode");
		SearchResult sr= logicProductionDispatchingService.findDispatchingDetailBySCS(scs);
		OutJsonGrid out = new OutJsonGrid(sr);
		out.printJSon(response);
	}
	
	/**
	 * 查询物料入库的价格
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping("/priceMaterails")
	public String priceMaterails(HttpServletRequest request,
			HttpServletResponse response, Model model){ 
		model.addAttribute("whList",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return PRICE;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/priceMaterailsList")
	public void priceMaterailsList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		JqGridHandler handler= new JqGridHandler(request);
		SearchConditions scs= new SearchConditions();
		handler.getWheres(scs);
		scs.setLimitClause(null);
		scs.setLimitPage(false);
		SearchResult sr= logicWarehouseInventoryService.findListByExample(scs);
		Map<String, LogicWarehouseInventoryDO> whiMap= new HashMap<String, LogicWarehouseInventoryDO>();
		List<LogicWarehouseInventoryDO> outList=sr.getResults();
		for(LogicWarehouseInventoryDO out:outList){
			//code mane model spec quanlity color whcode
			String key=(StringUtils.isEmpty(out.getZd004MaterialsCode())?null:out.getZd004MaterialsCode())+"_"+
						(StringUtils.isEmpty(out.getZd005MaterialsName())?null:out.getZd005MaterialsName())+"_"+
						(StringUtils.isEmpty(out.getZd007MaterialsModel())?null:out.getZd007MaterialsModel())+"_"+
						(StringUtils.isEmpty(out.getZd006MaterialsSpec())?null:out.getZd006MaterialsSpec())+"_"+
						(StringUtils.isEmpty(out.getZd008MaterialsQuanlity())?null:out.getZd008MaterialsQuanlity())+"_"+
						(StringUtils.isEmpty(out.getZd008MaterialsColor())?null:out.getZd008MaterialsColor())+"_"+
						(StringUtils.isEmpty(out.getZd001WhCode())?null:out.getZd001WhCode());
			whiMap.put(key, out);
		}
		Collection<SearchCondition> conditions=scs.getConditions();
		for(SearchCondition con:conditions){
			if("zd004MaterialsCode".equals(con.getField())){
				con.setField("zd002MaterialCode");
			}
			if("zd005MaterialsName".equals(con.getField())){
				con.setField("zd002MaterialName");
			}
			if("zd007MaterialsModel".equals(con.getField())){
				con.setField("zd003MaterialModel");
			}
			if("zd006MaterialsSpec".equals(con.getField())){
				con.setField("zd003MaterialSpec");
			}
			if("zd001WhName".equals(con.getField())){
				con.setField("zd001WhName");
			}
		}
		scs.setOrderBy("bizCreatorDate desc");
		scs.setRemovedProperty(null);
		List<LogicWarehouseHistoryDO> listHistory=this.logicWarehouseHistoryDAO.findListByCondition(scs);
		for(LogicWarehouseHistoryDO his:listHistory){
			//code mane model spec quanlity color whcode
			String key=(StringUtils.isEmpty(his.getZd002MaterialCode())?null:his.getZd002MaterialCode())+"_"+
						(StringUtils.isEmpty(his.getZd002MaterialName())?null:his.getZd002MaterialName())+"_"+
						(StringUtils.isEmpty(his.getZd003MaterialModel())?null:his.getZd003MaterialModel())+"_"+
						(StringUtils.isEmpty(his.getZd003MaterialSpec())?null:his.getZd003MaterialSpec())+"_"+
						(StringUtils.isEmpty(his.getZd003MaterialQuanlity())?null:his.getZd003MaterialQuanlity())+"_"+
						(StringUtils.isEmpty(his.getZd003MaterialColor())?null:his.getZd003MaterialColor())+"_"+
						(StringUtils.isEmpty(his.getZd001WhCode())?null:his.getZd001WhCode());
			LogicWarehouseInventoryDO whi=whiMap.get(key);
			if(whi==null){
				whi= new LogicWarehouseInventoryDO();
				whi.setZd001WhCode(his.getZd001WhCode());
				whi.setZd001WhName(his.getZd001WhName());
				whi.setZd004MaterialsCode(his.getZd002MaterialCode());
				whi.setZd005MaterialsName(his.getZd002MaterialName());
				whi.setZd007MaterialsModel(his.getZd003MaterialModel());
				whi.setZd006MaterialsSpec(his.getZd003MaterialSpec());
				whi.setZd008MaterialsColor(his.getZd003MaterialColor());
				whi.setZd008MaterialsQuanlity(his.getZd003MaterialQuanlity());
				whi.setZd008Unit(his.getZd010Unit());
				whi.setZd024Price(his.getZd005MateriaPrice());
				whiMap.put(key, whi);
			}else{
				continue;
			}
		}
		outList.clear();
		for(LogicWarehouseInventoryDO v:whiMap.values()){
			outList.add(v);
		}
		sr.setResults(outList);
		sr.setRecordCount(outList.size());
		OutJsonGrid out = new OutJsonGrid(sr);
		out.printJSon(response);
	}
	
	/**
	 * 销售的订单出库明细表
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping("/repSaleOrder")
	public String repSaleOrder(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		return SALE;
	}
	
	@RequestMapping("/repSaleOrderList")
	public void repSaleOrderList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		JqGridHandler handler= new JqGridHandler(request);
		SearchConditions scs= new SearchConditions();
		handler.getWheres(scs);
		scs.setRemovedProperty("gs.removed");
		scs.setOrderBy("gs.bizCreatorDate  desc");
		scs=oftenMothedUtil.addSearchConditionsByInMonth(scs, "gs.bizCreatorDate");
		scs.addCondition("gs.zd024Billstatus",BillStatusUtil.SES_STATUS_ONE,SearchCondition.OP_NOTEQUAL);
		SearchResult sr= logicProductionStorageOutService.findQuerySaleDetailByScs(scs);
		OutJsonGrid out = new OutJsonGrid(sr);
		out.printJSon(response);
	}
	
	/**
	 * 采购入库汇总表
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping("/pcswSum")
	public String pcswSum(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		return PCSWSUM;
	}
	
	@RequestMapping("/pcswSumList")
	public void pcswSumList(HttpServletRequest request, 
			HttpServletResponse response, Model model){
		JqGridHandler handler= new JqGridHandler(request);
		SearchConditions scs= new SearchConditions();
		handler.getWheres(scs);
		scs.setRemovedProperty(null);
		SearchResult sr = logicWarehouseDetailsService.findQueryPcswToSummary(scs);
		OutJsonGrid out = new OutJsonGrid(sr);
		out.printJSon(response);
	}
	
	@RequestMapping("pcswDetail")
	public String pcswDetail(HttpServletRequest request, 
			HttpServletResponse response, Model model) throws Exception {
		String zdMaterId = request.getParameter("materId");
		String zdMaterName = request.getParameter("materName");
		String zdMaterCode = request.getParameter("materCode");
		String zdMaterSpec = request.getParameter("materSpec");
		String zdMaterModel = request.getParameter("materModel");
		String zdBeginDate = request.getParameter("markBeginDate");
		String zdEndDate = request.getParameter("markEndDate");
		model.addAttribute("zdMaterId", zdMaterId);
		model.addAttribute("zdMaterName", zdMaterName);
		model.addAttribute("zdMaterCode", zdMaterCode);
		model.addAttribute("zdMaterSpec", zdMaterSpec);
		model.addAttribute("zdMaterModel", zdMaterModel);
		model.addAttribute("zdBeginDate", zdBeginDate);
		model.addAttribute("zdEndDate", zdEndDate);
		return  PCSWDET;
	}
	@RequestMapping("/storeReport")
	public String storeReport(HttpServletRequest request, 
			HttpServletResponse response){
		return STOREAll;
	}
	@RequestMapping("/storeReportList")
	public void storeReportList(HttpServletRequest request, 
			HttpServletResponse response){
		JqGridHandler handler= new JqGridHandler(request);
		SearchConditions scs= new SearchConditions();
		handler.getWheres(scs);
		scs.setRemovedProperty(null);
		String now=request.getParameter("now");
		if(null==now||StringUtils.isEmpty(now)){
			SimpleDateFormat sdf= new SimpleDateFormat("MM");
			scs.addCondition("mon", sdf.format(new Date()));
		}else{
			scs.addCondition("mon", now);
		}
		//获取出库总数，出库总金额 入库总数 入库总金额
		
		//获取现在的库存数
		scs.clearCondition();
		scs.setRemovedProperty("logic_warehouse_inventory.removed");//库存明细
	
		//获取期初数量 盘点表 （月度盘点）
		/*logicWhCheckTaskService. dao 未完成*/
		
	
		//获取期初数  a 判断现在的月份是否盘点结束  盘点结束取盘点数作为期初数 期初金额等于盘点数乘以上月最后一次平均价（表为平均价表的最后一次）
		//没有结束 期初数量 = 现在的库存数+出库总数-入库总数
		
		
	
	}
	
	/*
	 * 月末统计报表
	 */
	@RequestMapping("/endMonth")
	public String endMonth(HttpServletRequest request, HttpServletResponse response, Model model)throws Exception{
		model.addAttribute("whList",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return ENDMONTH;
	}
	
	@RequestMapping("/endMonthList")
	public void endMonthList(HttpServletRequest request, HttpServletResponse response){
		try {
			SearchResult sr=new SearchResult();
			long beginTime = System.currentTimeMillis();
			if(StringUtils.isEmpty(request.getParameter("date"))){
				throw new SyBaseException("请选择时间");
			}
			List<LogicWarehouseEndMonthSumVO> list= this.excelExportService.findEndMonth(request);
			sr.setResults(list);
			sr.setRecordCount(list.size());
			long endTime = System.currentTimeMillis();
			System.out.println("Query Time = "+((endTime - beginTime)/1000));
			OutJsonGrid out = new OutJsonGrid(sr);
			out.printJSon(response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping("/in")
	public String inExcel(HttpServletRequest request, HttpServletResponse response, Model model)throws Exception{
		model.addAttribute("whList",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return ENDMONTH;
	}
	
}
